﻿using Order.MicroService.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Order.MicroService.IRepository
{
    public interface IBaseRepository<TEntity> where TEntity : class,new()
    {
        #region 查询
        /// <summary>
        /// 获取单个实体 
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        TEntity GetEntity(Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 异步获取单个实体
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<TEntity> GetEntityAsync(Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 根据Id获取实体
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        TEntity GetEntityById(int Id);
        /// <summary>
        /// 异步根据Id获取实体
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        Task<TEntity> GetEntityByIdAsync(int Id);
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        IEnumerable<TEntity> GetList(Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 异步获取列表
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        Pagination<TEntity> GetPageList(int pageIndex, int pageSize, Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 异步获取分页列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        Task<Pagination<TEntity>> GetPageListAsync(int pageIndex, int pageSize, Expression<Func<TEntity, bool>> where);
        #endregion

        #region 修改      
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        int Update(TEntity entity);
        /// <summary>
        /// 异步更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(TEntity entity);
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete(TEntity entity);
        /// <summary>
        /// 异步删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(TEntity entity);
        #endregion

        #region 增加
        /// <summary>
        /// 增加一条
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int AddEntity(TEntity entity);
        /// <summary>
        /// 异步添加一条
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> AddEntityAsync(TEntity entity);
        /// <summary>
        /// 添加多条
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        int AddList(IEnumerable<TEntity> entities);
        /// <summary>
        /// 异步添加多条
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> AddListAsync(IEnumerable<TEntity> entities);
        #endregion
    }
}
